//
//  UIImageView+lvfjHelper.m
//  lvfj
//
//  Created by 吕飞俊 on 15/11/16.
//  Copyright © 2015年 Goudu KuaiEx Technology(Shenzhen)Co.,ltd. All rights reserved.
//   _          ______   _      _
//  | |        |  ____| (_)    | |
//  | |  __   _| |__ ___ _     | |_   _ _ __
//  | |  \ \ / /  __/ _ \ |_   | | | | | '_ \
//  | |___\ V /| | |  __/ | |__| | |_| | | | |
//  |______\_/ |_|  \___|_|\____/ \__,_|_| |_|
//

#import "UIImageView+lvfjHelper.h"

@implementation UIImageView (lvfjHelper)

//等比拉伸，超出不显示
-(void)setMiddleImage{
    [self setContentScaleFactor:[[UIScreen mainScreen] scale]];
    self.contentMode =  UIViewContentModeScaleAspectFill;
//    self.autoresizingMask = UIViewAutoresizingFlexibleHeight;//frame改变，则会自动调用
    self.clipsToBounds  = YES;
}

//根据主题色改变图片（按钮）颜色
-(void)setimgage{
    UIColor *appThemeColor = UIColor.blueColor;
    UIColor *backgroundColor;
    CGFloat borderWidth;
    
    BOOL isblueBack = YES;
    if (isblueBack) {
        //蓝色背景，白色图标
        backgroundColor = appThemeColor;
        borderWidth = 0;
    }else{
        //白色背景，蓝色图标，蓝色边框
        backgroundColor = UIColor.clearColor;
        borderWidth = 1.5;
    }
    
    self.image = [UIImage imageNamed:@"image_color"];
    self.backgroundColor = backgroundColor;
    self.layer.borderWidth = borderWidth;
    self.layer.borderColor = appThemeColor.CGColor;
}

//改变图片颜色
/*
 美工切出来一个返回按钮  颜色是黄色 但有一个页面需要这个返回按钮是红色  那就没必要美工再切一张红色的按钮，而是利用UIImageRenderingModeAlwaysTemplate这个属性把黄色按钮改成红色
 A
 */
-(void)changeImageColor:(UIImage *)image color:(UIColor *)color{
//    UIImage *image = [UIImage imageNamed:@"image_color"];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    self.image = image;
    self.tintColor = color;
//    self.tintColor = [UIColor purpleColor];
}
/*
 B
 UIButton 的点击状态  因为UIButton设置背景色  点击UIButton  是没有点击色的  但是UIButton的背景图片有点击色 那就可以利用UIImageRenderingModeAlwaysTemplate这个属性改变任意一张图片的颜色为我们需要的那个颜色
 例  代码
  
     UIImage *image = [UIImage imageNamed:@"111.jpg"];
     image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
     UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
     btn.tintColor = [UIColor brownColor];
     [btn setBackgroundImage:image forState:UIControlStateNormal];
     [self.view addSubview:btn]*/

@end
